package com.little.pattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by littleshu on 18/5/5.
 */
public class XiaoMing implements Subject {
    private List<Observer> observers;

    public XiaoMing() {
        observers = new ArrayList<>();
    }

    @Override
    public void registerObserver(Observer observer) {
        this.observers.add(observer);
    }

    @Override
    public void notifyObserver() {
        for (Observer observer : this.observers) {
            observer.update();
        }
    }

    @Override
    public void removeObserver(Observer observer) {
        this.observers.remove(observer);
    }

    public void listen() {
        System.out.println("小明在很认真听讲");
    }
}
